#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import json

sys.path.append(
    os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "qtrade")
)

import requests

# 测试
base_url = "http://localhost:8000/stock/"

headers = {
}
import db


def test_run_all_indicator_strategy():
    url = base_url + 'run_indicator_strategy'
    res = requests.get(url)
    content = json.loads(res.content)
    print(content)


def test_check_one_strategy_trigger():
    from controllers.stock import check_one_strategy_trigger
    strategy = db.StrategyTB.find_one(name = 'RSI30回弹盈利小于5')
    if not strategy:
        raise Exception("不存在此策略")
    data = dict(
            ts_code = '600016.SH',
            strategy = strategy,
            cal_date_int = 20220314
            )
    res = check_one_strategy_trigger(**data)
    print(res)

def test_indicator_trigger():
    from controllers.stock import indicator_trigger
    data = dict(
            ts_code = '600016.SH',
            next_trade_day = 20220314,
            strategy_name = 'RSI30回弹盈利小于5',
            )
    res = indicator_trigger(**data)
    print(res)


if __name__ == '__main__':
    test_indicator_trigger()


